package com.parenting.feigncontroller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.parenting.entities.SystemUserDO;
import com.parenting.feign.controller.IFeignSystemUserController;
import com.parenting.feign.entities.ShopAndUserFeignDTO;
import com.parenting.model.User;
import com.parenting.service.SystemResourcesService;
import com.parenting.service.SystemUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class FeignSystemUserController implements IFeignSystemUserController {

    @Autowired
    private SystemUserService systemUserService;

    @Override
    public void shopAndUser(ShopAndUserFeignDTO shopAndUserFeignDTO) {
        systemUserService.ShopAndUser(shopAndUserFeignDTO);
    }

    @Override
    public boolean ChekShopClaim(String shopId) {
        log.info("=======ChekShopClaim========== {}",shopId);
        LambdaQueryWrapper<SystemUserDO> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SystemUserDO::getShopId,shopId);
        List<SystemUserDO> systemUserDOS = systemUserService.getBaseMapper().selectList(wrapper);

        return (null==systemUserDOS||systemUserDOS.size()<=0)?true:false;
    }

    @Override
    public boolean ChekShopClaimUser(String userId) {
        log.info("=======ChekShopClaimUser========== {}",userId);
        SystemUserDO byId = systemUserService.getById(userId);
        if (StringUtils.isEmpty(byId.getShopId())){
            return false;
        }
        return true;
    }


    @Override
    public String getShopIdByLoginUserId(String userId) {
        SystemUserDO byId = systemUserService.getById(userId);
        return byId.getShopId();
    }

    @Override
    public User getUserByAccount(String username) {
        SystemUserDO userByUserName = systemUserService.findUserByUserName(username);
        return BeanUtil.copyProperties(userByUserName,User.class);
    }


    @Autowired
    private SystemResourcesService systemResourcesService;


    @Override
    public List<String> findCodeByUserId(String userId) {
        return systemResourcesService.findCodeByUserId(userId);
    }




}
